#include "stdafx.h"
#include "win_scintilla.h"
#include "ch_log.h"

#pragma comment(lib,"comctl32.lib")


HINSTANCE win_scintilla::_hdll = ::LoadLibrary(_T("SciLexer.DLL"));

win_scintilla::win_scintilla()
{
    _dwExStyle = WS_EX_PALETTEWINDOW;
    _dwStyle = WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_CLIPCHILDREN | WS_EX_RTLREADING;
    _tcscpy_s(_szClassName, _T("Scintilla"));
    _scFunc = NULL;
    _scPtr = NULL;
}


win_scintilla::~win_scintilla()
{
}

bool win_scintilla::reg_class(HINSTANCE hInstance, PTCHAR pszClassName)
{
    if(hInstance)
    {
        _hInstance = hInstance;   
    }
    else if(NULL == _hInstance)
    {
        _hInstance = GetModuleHandle(NULL);
    }

	if (!_hdll)
	{
		LOG::error(ERR_CODE_SYSTEM, __FILE__ " line %d: " __FUNCTION__ "() Failed to load 'SciLexer.DLL'", __LINE__);
		throw int(106901);
	}
    _tcscpy_s(_szClassName, _T("Scintilla"));

    return 1;
}

bool win_scintilla::create(HWND hWndParent)
{
    bool bRes = win_base::create(hWndParent);
	_scFunc = (int (__cdecl *)(void *,int,int,int))SendMessage(_hWnd,SCI_GETDIRECTFUNCTION,0,0);
	_scPtr = (void *)SendMessage(_hWnd,SCI_GETDIRECTPOINTER,0,0);    
    return bRes;
}
